/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.secure.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author xljan
 */
@Entity
@Table(name = "secure_user")
@XmlRootElement
@Cacheable(false)
@NamedQueries({
    @NamedQuery(name = "SecureUser.findAll", query = "SELECT s FROM SecureUser s"),
    @NamedQuery(name = "SecureUser.findByIdUser", query = "SELECT s FROM SecureUser s WHERE s.idUser = :idUser"),
    @NamedQuery(name = "SecureUser.findByUsername", query = "SELECT s FROM SecureUser s WHERE s.username = :username"),
    @NamedQuery(name = "SecureUser.findByEmail", query = "SELECT s FROM SecureUser s WHERE s.email = :email"),
    @NamedQuery(name = "SecureUser.findByCreateTimestamp", query = "SELECT s FROM SecureUser s WHERE s.createTimestamp = :createTimestamp"),
    @NamedQuery(name = "SecureUser.findByPostalCode", query = "SELECT s FROM SecureUser s WHERE s.postalCode = :postalCode"),
    @NamedQuery(name = "SecureUser.findByGender", query = "SELECT s FROM SecureUser s WHERE s.gender = :gender")})
public class SecureUser implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_user")
    private Integer idUser;
    @Size(max = 100)
    @Column(name = "username")
    private String username;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 255)
    @Column(name = "email")
    private String email;
    @Lob
    @Size(max = 65535)
    @Column(name = "firstname")
    private String firstname;
    @Lob
    @Size(max = 65535)
    @Column(name = "lastname")
    private String lastname;
    @Lob
    @Size(max = 65535)
    @Column(name = "passwd")
    private String passwd;
    @Lob
    @Size(max = 65535)
    @Column(name = "street")
    private String street;
    @Column(name = "create_timestamp")
    private BigInteger createTimestamp;
    @Column(name = "postal_code")
    private Integer postalCode;
    // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
    @Lob
    @Size(max = 65535)
    @Column(name = "phone")
    private String phone;
    @Lob
    @Size(max = 65535)
    @Column(name = "info")
    private String info;
    @Lob
    @Size(max = 65535)
    @Column(name = "city")
    private String city;
    @Column(name = "gender")
    private Integer gender;
    @JoinTable(name = "secure_user_group", joinColumns = {
        @JoinColumn(name = "id_user", referencedColumnName = "id_user")}, inverseJoinColumns = {
        @JoinColumn(name = "id_group", referencedColumnName = "id_group")})
    @ManyToMany
    private Collection<SecureGroup> secureGroupCollection;

    public SecureUser() {
    }

    public SecureUser(Integer idUser) {
        this.idUser = idUser;
    }

    public Integer getIdUser() {
        return idUser;
    }

    public void setIdUser(Integer idUser) {
        this.idUser = idUser;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public BigInteger getCreateTimestamp() {
        return createTimestamp;
    }

    public void setCreateTimestamp(BigInteger createTimestamp) {
        this.createTimestamp = createTimestamp;
    }

    public Integer getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(Integer postalCode) {
        this.postalCode = postalCode;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    @XmlTransient
    public Collection<SecureGroup> getSecureGroupCollection() {
        return secureGroupCollection;
    }

    public void setSecureGroupCollection(Collection<SecureGroup> secureGroupCollection) {
        this.secureGroupCollection = secureGroupCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUser != null ? idUser.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SecureUser)) {
            return false;
        }
        SecureUser other = (SecureUser) object;
        if ((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fyx.secure.entity.SecureUser[ idUser=" + idUser + " ]";
    }
}
